home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / libs / dummylib.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  6KB  |  246 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: dummylib.c,v 1.7 1996/10/24 15:51:27 aros Exp $
  4.     $Log: dummylib.c,v $
  5.     Revision 1.7  1996/10/24 15:51:27  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.6  1996/10/23 14:05:18  aros
  9.     Missing include
  10.  
  11.     Revision 1.5  1996/09/13 17:57:09  digulla
  12.     Use IPTR
  13.  
  14.     Revision 1.4  1996/09/12 14:52:04  digulla
  15.     Use correct way to access external names (was missing)
  16.  
  17.     Revision 1.3  1996/08/13 15:35:11  digulla
  18.     Replaced AROS_LA by AROS_LHA
  19.  
  20.     Revision 1.2  1996/08/01 17:41:28  digulla
  21.     Added standard header for all files
  22.  
  23.     Desc:
  24.     Lang:
  25. */
  26. #include <exec/types.h>
  27. #include <exec/resident.h>
  28. #include <clib/exec_protos.h>
  29. #include <aros/libcall.h>
  30. #ifdef __GNUC__
  31. #   include "dummylib_gcc.h"
  32. #endif
  33. #include "initstruct.h"
  34. #include <stddef.h>
  35.  
  36. struct inittable;
  37. extern const char name[];
  38. extern const char version[];
  39. extern const APTR inittabl[4];
  40. extern void *const functable[];
  41. extern const struct inittable datatable;
  42. extern struct dummybase *AROS_SLIB_ENTRY(init,dummy)();
  43. extern struct dummybase *AROS_SLIB_ENTRY(open,dummy)();
  44. extern BPTR AROS_SLIB_ENTRY(close,dummy)();
  45. extern BPTR AROS_SLIB_ENTRY(expunge,dummy)();
  46. extern int AROS_SLIB_ENTRY(null,dummy)();
  47. extern ULONG AROS_SLIB_ENTRY(add,dummy)();
  48. extern ULONG AROS_SLIB_ENTRY(asl,dummy)();
  49. extern const char end;
  50.  
  51. int entry(void)
  52. {
  53.     /* If the library was executed by accident return error code. */
  54.     return -1;
  55. }
  56.  
  57. const struct Resident resident=
  58. {
  59.     RTC_MATCHWORD,
  60.     (struct Resident *)&resident,
  61.     (APTR)&end,
  62.     RTF_AUTOINIT,
  63.     1,
  64.     NT_LIBRARY,
  65.     0,
  66.     (char *)name,
  67.     (char *)&version[6],
  68.     (ULONG *)inittabl
  69. };
  70.  
  71. const char name[]="dummy.library";
  72.  
  73. const char version[]="$VER: dummy 1.0 (28.3.96)\n\015";
  74.  
  75. const APTR inittabl[4]=
  76. {
  77.     (APTR)sizeof(struct dummybase),
  78.     (APTR)functable,
  79.     (APTR)&datatable,
  80.     &AROS_SLIB_ENTRY(init,dummy)
  81. };
  82.  
  83. void *const functable[]=
  84. {
  85.     &AROS_SLIB_ENTRY(open,dummy),
  86.     &AROS_SLIB_ENTRY(close,dummy),
  87.     &AROS_SLIB_ENTRY(expunge,dummy),
  88.     &AROS_SLIB_ENTRY(null,dummy),
  89.     &AROS_SLIB_ENTRY(add,dummy),
  90.     &AROS_SLIB_ENTRY(asl,dummy),
  91.     (void *)-1
  92. };
  93.  
  94. struct inittable
  95. {
  96.     S_CPYO(1,1,B);
  97.     S_CPYO(2,1,L);
  98.     S_CPYO(3,1,B);
  99.     S_CPYO(4,1,W);
  100.     S_CPYO(5,1,W);
  101.     S_CPYO(6,1,L);
  102.     S_END (end);
  103. };
  104.  
  105. #define O(n) offsetof(struct dummybase,n)
  106.  
  107. const struct inittable datatable=
  108. {
  109.     { { I_CPYO(1,B,O(library.lib_Node.ln_Type)), { NT_LIBRARY } } },
  110.     { { I_CPYO(1,L,O(library.lib_Node.ln_Name)), { (IPTR)name } } },
  111.     { { I_CPYO(1,B,O(library.lib_Flags       )), { LIBF_SUMUSED|LIBF_CHANGED } } },
  112.     { { I_CPYO(1,W,O(library.lib_Version     )), { 1 } } },
  113.     { { I_CPYO(1,W,O(library.lib_Revision    )), { 0 } } },
  114.     { { I_CPYO(1,L,O(library.lib_IdString    )), { (IPTR)&version[6] } } },
  115.     I_END ()
  116. };
  117.  
  118. #undef O
  119.  
  120. AROS_LH2(struct dummybase *, init,
  121.  AROS_LHA(struct dummybase *, dummybase, D0),
  122.  AROS_LHA(BPTR,               segList,   A0),
  123.        struct ExecBase *, SysBase, 0, dummy)
  124. {
  125.     AROS_LIBFUNC_INIT
  126.     /* This function is single-threaded by exec by calling Forbid. */
  127.  
  128.     /* Store arguments */
  129.     dummybase->sysbase=SysBase;
  130.     dummybase->seglist=segList;
  131.  
  132.     /* You would return NULL here if the init failed. */
  133.     return dummybase;
  134.     AROS_LIBFUNC_EXIT
  135. }
  136.  
  137. /* Use This from now on */
  138. #ifdef SysBase
  139. #undef SysBase
  140. #endif
  141. #define SysBase dummybase->sysbase
  142.  
  143. AROS_LH1(struct dummybase *, open,
  144.  AROS_LHA(ULONG, version, D0),
  145.        struct dummybase *, dummybase, 1, dummy)
  146. {
  147.     AROS_LIBFUNC_INIT
  148.     /*
  149.     This function is single-threaded by exec by calling Forbid.
  150.     If you break the Forbid() another task may enter this function
  151.     at the same time. Take care.
  152.     */
  153.  
  154.     /* Keep compiler happy */
  155.     version=0;
  156.  
  157.     /* I have one more opener. */
  158.     dummybase->library.lib_OpenCnt++;
  159.     dummybase->library.lib_Flags&=~LIBF_DELEXP;
  160.  
  161.     /* You would return NULL if the open failed. */
  162.     return dummybase;
  163.     AROS_LIBFUNC_EXIT
  164. }
  165.  
  166. AROS_LH0(BPTR, close, struct dummybase *, dummybase, 2, dummy)
  167. {
  168.     AROS_LIBFUNC_INIT
  169.     /*
  170.     This function is single-threaded by exec by calling Forbid.
  171.     If you break the Forbid() another task may enter this function
  172.     at the same time. Take care.
  173.     */
  174.  
  175.     /* I have one fewer opener. */
  176.     if(!--dummybase->library.lib_OpenCnt)
  177.     {
  178.     /* Delayed expunge pending? */
  179.     if(dummybase->library.lib_Flags&LIBF_DELEXP)
  180.         /* Then expunge the library */
  181.         return expunge();
  182.     }
  183.     return 0;
  184.     AROS_LIBFUNC_EXIT
  185. }
  186.  
  187. AROS_LH0(BPTR, expunge, struct dummybase *, dummybase, 3, dummy)
  188. {
  189.     AROS_LIBFUNC_INIT
  190.  
  191.     BPTR ret;
  192.     /*
  193.     This function is single-threaded by exec by calling Forbid.
  194.     Never break the Forbid() or strange things might happen.
  195.     */
  196.  
  197.     /* Test for openers. */
  198.     if(dummybase->library.lib_OpenCnt)
  199.     {
  200.     /* Set the delayed expunge flag and return. */
  201.     dummybase->library.lib_Flags|=LIBF_DELEXP;
  202.     return 0;
  203.     }
  204.  
  205.     /* Get rid of the library. Remove it from the list. */
  206.     Remove(&dummybase->library.lib_Node);
  207.  
  208.     /* Get returncode here - FreeMem() will destroy the field. */
  209.     ret=dummybase->seglist;
  210.  
  211.     /* Free the memory. */
  212.     FreeMem((char *)dummybase-dummybase->library.lib_NegSize,
  213.         dummybase->library.lib_NegSize+dummybase->library.lib_PosSize);
  214.  
  215.     return ret;
  216.     AROS_LIBFUNC_EXIT
  217. }
  218. AROS_LH0I(int, null, struct dummybase *, dummybase, 4, dummy)
  219. {
  220.     AROS_LIBFUNC_INIT
  221.     return 0;
  222.     AROS_LIBFUNC_EXIT
  223. }
  224.  
  225. AROS_LH2I(ULONG, add,
  226.     AROS_LHA(ULONG,a,D0),
  227.     AROS_LHA(ULONG,b,D1),
  228.     struct dummybase *,dummybase,5,dummy)
  229. {
  230.     AROS_LIBFUNC_INIT
  231.     return a+b;
  232.     AROS_LIBFUNC_EXIT
  233. }
  234.  
  235. AROS_LH2I(ULONG, asl,
  236.     AROS_LHA(ULONG,a,D0),
  237.     AROS_LHA(ULONG,b,D1),
  238.     struct dummybase *,dummybase,6,dummy)
  239. {
  240.     AROS_LIBFUNC_INIT
  241.     return a<<b;
  242.     AROS_LIBFUNC_EXIT
  243. }
  244.  
  245. const char end=0;
  246.